//提现页面 0
//确定提现页面 1
//提交提现页面 2
//添加银行卡页面 3

define(function(require, exports, module){
	"require:nomunge,exports:nomunge,module:nomunge";
	//异步请求
var wind_async=require('ddf_wind_async');

var dialog=require('component-dialog');
	
var base=require('component-base');

var history = require('component-history');
	
require('component-page');
	/**
	 * 提现操作
	 */
exports.init=function(m){
    window.$ddf_withdraw = m;
    loadWithdrawList(); //加载提现记录
};
	
	/**
	 * 加载提现记录
	 */
	function loadWithdrawList(){
    history.addHis(this,arguments);
    var htmlStr = "";
    htmlStr += '<div id="content-header"><div id="breadcrumb"> <a href=javascript:load("'
			+ ddf.index.index_js
			+ '") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href="javascript:void(0)" class="current">提现</a></div></div>';//<h1>提现</h1>
	htmlStr += '<div class="container-fluid">';
//	htmlStr += '<hr/>';
	htmlStr += '<div class="row-fluid">';
	htmlStr += '<div class="span12">';
	htmlStr += '<div id="alert-tips0" ></div>';

	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title">';
	htmlStr += '<span class="icon"><i class="icon-money"></i></span>';
	htmlStr += '<h5>账户</h5>';
	htmlStr += '</div>        ';
	htmlStr += '<div class="widget-content clearfix">';
	htmlStr += '<div class="fontsize">';
	htmlStr += '<span>账户余额：<span class="color_f90" id="show_balance"></span>元</span>';
	htmlStr += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
	htmlStr += '<span>可提现余额：<span class="color_f90" id="show_minBalance"></span>元</span>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>   ';
	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title">';
	htmlStr += '<span class="icon"><i class="icon-pencil"></i></span>';
	htmlStr += '<h5>操作</h5>';
	htmlStr += '</div>  ';
	htmlStr += '<div class="widget-content">';
	htmlStr += '<div class="div-btn" id="buttonBox">';
	htmlStr += '<button class="btn btn-success" id="bindBankCardBtn" type="button" onclick=$ddf_withdraw.bindingbankcardPage()>添加银行卡</button>';

	
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '<div id="confirmDiv">';
	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title"> <span class="icon"><i class="icon-th"></i></span>';
	htmlStr += '<h5>提取余额到银行卡</h5>';
	htmlStr += '</div>';
	htmlStr += '<div class="widget-content nopadding">';
	htmlStr += '<form class="form-horizontal">';
	htmlStr += '<div class="control-group" id="control-group-amount">';
	htmlStr += '<label class="control-label">提现金额：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input type="text" id="input-amount" class="input_height"/>';
	htmlStr += ' <span class="help-inline" id="warning"></span>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">银行账户：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<span class="inp_span" id="show_bankNumber_sort"></span>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">银行名称：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<span class="inp_span" id="show_bankName"></span>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">账户姓名：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<span class="inp_span" id="show_accountName"></span>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '<div class="form-actions">';
	htmlStr += '<button class="btn btn-primary" id="btnNext" type="button" onClick=$ddf_withdraw.nextStatus()>下一步</button>';
	htmlStr += '</div>';
	htmlStr += '</form> ';
	htmlStr += '</div>  ';
	htmlStr += '</div> ';
	
	
	htmlStr += '</div>';
	
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';

	showDiv("content0");

	$("#content0").html(htmlStr); // 在页面上显示

	if (bindBankFlag) {
		base.tips("银行卡绑定成功");
		bindBankFlag = false;
	}

	$("#input-amount").change(function() {
		
		var amount=$("#input-amount").val();
		var minBalance=$("#show_minBalance").html();
		
		if(isNull(amount)|| !isNumber2Decimal(amount)){
			$("#warning").removeClass("help-inline");
			$("#warning").html(""); 
			clearErrorMessage("control-group-amount");
			addErrorMessage("control-group-amount","input-amount","提现金额非法");
			
		}else{
			if(parseFloat(amount) > parseFloat(minBalance)){
				$("#warning").removeClass("help-inline");
				$("#warning").html("");
				addErrorMessage("control-group-amount","input-amount","余额不足");
			}else{
				withDraw["amount"]=$("#input-amount").val();
				clearErrorMessage("control-group-amount");
				$("#warning").addClass("help-inline");
				$("#warning").html(warmTips);
			}
		}
	});
	getWithdraw(); // 获取用户的基本信息
	}
	

	/**
	 * 提现数据
	 */
	function getWithdraw() {

		base.showLoading();

		eval(Wind.compile("async",function(){
			
			var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.withDrawSettle.withdraw,""));
			
			getWithDrawCallBack(data);
			
		}))().start();

	}

	/**
	 * 提现数据的回调函数
	 * 
	 * @param data
	 */
	var withDraw = {};// 提现传递参数
	var warmTips="";//警告提示文字
	function getWithDrawCallBack(data) {
		
//		if(data["BANDINGBANKCARD"]!=true){
// 		   $("#bindBankCardBtn").css("display","none");
// 	   }
 	   
// 	   if(data["CONFIRM"]!=true){
// 		   
// 			$("#confirmDiv").css("display","none");
// 	   }
		
     
       if (data["code"] == 1) {
    	   	
    	    $("#show_balance").html(isNaN(data["balance"])?"0":parseFloat(data["balance"]));
	   		$("#show_minBalance").html(isNaN(data["settleAmount"])?"0":parseFloat(data["settleAmount"]));
	   		$("#show_bankName").html(data["bankName"]);
	   		$("#show_bankNumber_sort").html(data["bankNumber_sort"]);
	   		$("#show_accountName").html(data["accountName"]);
	   		
	       	 $("#warning").html(data["tips"]);
	       	 warmTips= $("#warning").html();
	       	
	       	withDraw["min"]=parseFloat(data["min"]);
	   		withDraw["balance"]=parseFloat(data["balance"]);
	   		withDraw["accountId"]=data["accountId"];
	   		withDraw["bankNumber"]=data["bankNumber"];
	   		withDraw["accountName"]=data["accountName"];
	   		withDraw["bankNumber_sort"]=data["bankNumber_sort"];
	   		withDraw["bankName"]=data["bankName"];
	   		
			$("#btnNext").attr("disabled", false);
		} else if(data["code"] == "-2"){
			
			//SHOP-30
			$("#show_balance").html(parseFloat(data["balance"]));
	   		$("#show_minBalance").html(parseFloat(data["settleAmount"]));
			
			$("#btnNext").attr("disabled", true);
			base.tips_error(data["message"]);
		}else {
			//SHOP-30
			if(typeof(data.balance) != "undefined"){
				$("#show_balance").html(parseFloat(data["amount"]));
				$("#show_minBalance").html(parseFloat(data["minBalance"]));
			}
			$("#btnNext").attr("disabled", true);
			base.tips_error(data["message"]);
		}

		base.cancelLoading();
	}

	function nextStatus() {

		var amount = $("#input-amount").val();
		var minBalance = $("#show_minBalance").html();

		if (isNull(amount) || !isNumber2Decimal(amount) || amount <= 0) {
			addErrorMessage("control-group-amount", "input-amount", "提现金额非法");

		} else {
			if (parseFloat(amount) > parseFloat(minBalance)) {
				addErrorMessage("control-group-amount", "input-amount", "余额不足");
			} else {
				withDraw["amount"] = $("#input-amount").val();
				clearErrorMessage("control-group-amount");
				confirmPage();
			}

		}

	}

	/**
	 * 确认提现信息
	 */
	function confirmPage() {

		history.addHis(this,arguments);
		var htmlStr = "";
		htmlStr += '<div id="content-header"><div id="breadcrumb"> <a href=javascript:load("'
				+ ddf.index.index_js
				+ '") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href=javascript:showDiv("content0") >提现</a><a href="javascript:void(0)" class="current">提现-确认提现信息</a></div></div>';//<h1>提现-确认提现信息</h1>
		htmlStr += '<div class="container-fluid">';
//		htmlStr += '<hr/>';
		htmlStr += '<div class="row-fluid">';
		htmlStr += '<div class="span12">';
		htmlStr += '<div id="alert-tips1" ></div>';

		htmlStr += '<div class="widget-box">';
		htmlStr += '<div class="widget-title"> <span class="icon"><i class="icon-th"></i></span>';
		htmlStr += '<h5>确认提现信息</h5>';
		htmlStr += '</div>';
		htmlStr += '<div class="widget-content nopadding">';
		htmlStr += '<form class="form-horizontal">';
		htmlStr += '<div class="control-group" id="control-group-amount">';
		htmlStr += '<label class="control-label">提现金额：</label>';
		htmlStr += '<div class="controls">';
		htmlStr += '<span class="inp_span" id="show-amount-confirm">'
				+ withDraw["amount"] + '  &nbsp;&nbsp; 元</span>';
		// htmlStr += ' <span class="help-inline">
		// 提示：提现金额小于等于1000.0元收取2.0元手续费</span>';
		htmlStr += '</div>';
		htmlStr += '</div>';
		htmlStr += '<div class="control-group">';
		htmlStr += '<label class="control-label">银行账户：</label>';
		htmlStr += '<div class="controls">';
		htmlStr += '<span class="inp_span" id="show_bankNumber_sort_confirm">'
				+ withDraw["bankNumber_sort"] + '</span>';
		htmlStr += '</div>';
		htmlStr += '</div>';
		htmlStr += '<div class="control-group">';
		htmlStr += '<label class="control-label">银行名称：</label>';
		htmlStr += '<div class="controls">';
		htmlStr += '<span class="inp_span" id="show_bankName-confirm">'
				+ withDraw["bankName"] + '</span>';
		htmlStr += '</div>';
		htmlStr += '</div>';
		htmlStr += '<div class="control-group">';
		htmlStr += '<label class="control-label">账户姓名：</label>';
		htmlStr += '<div class="controls">';
		htmlStr += '<span class="inp_span" id="show_accountName-confirm">'
				+ withDraw["accountName"] + '</span>';
		htmlStr += '</div>';
		htmlStr += '</div>';

		htmlStr += '<div class="control-group" id="control-group-payPassword">';
		htmlStr += '<label class="control-label">支付密码：</label>';
		htmlStr += '<div class="controls">';
		htmlStr += '<input type="password" id="payPassword" />';
		htmlStr += '</div>';
		htmlStr += '</div>';

		htmlStr += '<div class="form-actions">';
		htmlStr += ' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
		htmlStr += '<button class="btn btn-primary" type="button" onClick=$ddf_withdraw.showDiv("content0")>返回上一步</button> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
		htmlStr += '<button class="btn btn-primary" type="button" onClick=$ddf_withdraw.confirm()>确认提现</button>';
		htmlStr += '</div>';
		htmlStr += '</form> ';
		htmlStr += '</div>  ';
		htmlStr += '</div> ';

		htmlStr += '</div>';
		htmlStr += '</div>';
		htmlStr += '</div>';

		showDiv("content1");

		$("#content1").html(htmlStr);
		
		/**
		 * 支付密码的验证
		 */
		$("#payPassword").change(function() {
			var payPassword = $("#payPassword").val();
			
			if(isNull(payPassword)){
				addErrorMessage("control-group-payPassword","payPassword","支付密码不为空");  //提示语
			}else{
				if(!isPayPassword(payPassword)){
				   addErrorMessage("control-group-payPassword","payPassword","支付密码为6为数字，请重新输入。");  //提示语
				}else{
					clearErrorMessage("control-group-payPassword");
				}
			}
		});

	}

	/**
	 * 提交提现要求
	 */
	function confirm() {

		var payPassword = MD5($("#payPassword").val());

		_sign_key = MD5(withDraw["accountId"] + withDraw["amount"]
				+ withDraw["bankNumber"] + withDraw["bankName"]
				+ withDraw["accountName"] + payPassword);

		var params = {

			"accountId" : withDraw["accountId"],
			"bankNumber" : withDraw["bankNumber"],
			"bankName" : withDraw["bankName"],
			"accountName" : withDraw["accountName"],
			"amount" : withDraw["amount"],
			"paypwd" : payPassword,
			"_sign_key" : _sign_key

		};


		base.showLoading();

		eval(Wind.compile("async",function(){
			
			var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.withDrawSettle.settleApply,params));
			
			addwithdrawCallBack(data);
			
		}))().start();

	}

	function addwithdrawCallBack(data) {

		if (data["code"] == 1) {

			withdrawResultPage();

		} else {

			base.tips_error(data["message"]);

		}

		base.cancelLoading();
	}

	function withdrawResultPage() {
	    history.addHis(this,arguments);
		var htmlStr = "";

		htmlStr += '<div id="content-header"><div id="breadcrumb"> <a href=javascript:load("'
				+ ddf.index.index_js
				+ '") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href=javascript:showDiv("content0") >提现</a><a href="javascript:void(0)" class="current">提现-提现结果</a></div></div>';//<h1>提现-提现结果</h1>
		htmlStr += '<div class="container-fluid">';
//		htmlStr += '<hr/>';
		htmlStr += '<div class="row-fluid">';
		htmlStr += '<div class="span12">';
		htmlStr += '<div id="alert-tips2" ></div>';

		htmlStr += '<div class="widget-box">';
		htmlStr += '<div class="widget-title">';
		htmlStr += '<span class="icon"><i class="icon-pencil"></i></span>';
		htmlStr += '<h5>操作</h5>';
		htmlStr += '</div>  ';
		htmlStr += '<div class="widget-content">';
		htmlStr += '<div class="div-btn">';
		htmlStr += '<button class="btn btn-success" type="button" onclick=$ddf_withdraw.queryWithdrawSettle()>查看提现记录</button>';
		htmlStr += '</div>';
		htmlStr += '</div>';
		htmlStr += '</div>';

		htmlStr += '<div class="widget-box">';
		htmlStr += '<div class="widget-title"> <span class="icon"><i class="icon-th"></i></span>';
		htmlStr += '<h5>提现结果</h5>';
		htmlStr += '</div>';
		htmlStr += '<div class="widget-content nopadding">';
		htmlStr += '<form class="form-horizontal">';
		htmlStr += '<div class="control-group" id="control-group-amount">';
		htmlStr += '<label class="control-label">提现金额：</label>';
		htmlStr += '<div class="controls">';
		htmlStr += '<span class="inp_span" id="show-amount-confirm">'
				+ withDraw["amount"] + '  &nbsp;&nbsp; 元</span>';
		// htmlStr += ' <span class="help-inline">
		// 提示：提现金额小于等于1000.0元收取2.0元手续费</span>';
		htmlStr += '</div>';
		htmlStr += '</div>';
		htmlStr += '<div class="control-group">';
		htmlStr += '<label class="control-label">银行账户：</label>';
		htmlStr += '<div class="controls">';
		htmlStr += '<span class="inp_span" id="show_bankNumber_sort_confirm">'
				+ withDraw["bankNumber_sort"] + '</span>';
		htmlStr += '</div>';
		htmlStr += '</div>';
		htmlStr += '<div class="control-group">';
		htmlStr += '<label class="control-label">银行名称：</label>';
		htmlStr += '<div class="controls">';
		htmlStr += '<span class="inp_span" id="show_bankName-confirm">'
				+ withDraw["bankName"] + '</span>';
		htmlStr += '</div>';
		htmlStr += '</div>';
		htmlStr += '<div class="control-group">';
		htmlStr += '<label class="control-label">账户姓名：</label>';
		htmlStr += '<div class="controls">';
		htmlStr += '<span class="inp_span" id="show_accountName-confirm">'
				+ withDraw["accountName"] + '</span>';
		htmlStr += '</div>';
		htmlStr += '</div>';

		htmlStr += '</form> ';
		htmlStr += '</div>  ';
		htmlStr += '</div> ';

		htmlStr += '</div>';
		htmlStr += '</div>';
		htmlStr += '</div>';

		showDiv("content2");

		$("#content2").html(htmlStr);
	}

	// 自动跳到提现记录页面
	function queryWithdrawSettle() {
		$("#withdrawSettleSpan").click();

	}
	
	/**
	 * 查询银行列表和证件类型列表
	 */
	function getBanksParams(){
		var params={
				"page.pageNumber":1,
				"page.pageSize":10000
		        };
		eval(Wind.compile("async",function(){
			
			var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.withDrawSettle.getBanksParams,params));
			
			getBanksParamsCallBack(data);
			
		}))().start();
		
	}

	/**
	 * 查询银行列表和证件类型列表_回调函数
	 */
	function getBanksParamsCallBack(data){
		
		var htmlStr="";
		
		for(var i=0;i<data["banksListData"].length;i++){
			
			//htmlStr+='<li><a href="'+data["banksListData"][i]["bankNumber"]+'">'+data["banksListData"][i]["bankName"]+'</a></li>';
			if(i==0)
				bankId=data["banksListData"][i]["bankId"];
			
			htmlStr += '<option value="'+data["banksListData"][i]["bankId"]+'" >'+data["banksListData"][i]["bankName"]+data["banksListData"][i]["bankId"]+'</option>';

		}
		$("#select-bank-card").html(htmlStr);
		
		base.setSelectStyle();
		
		$("#select-bank-card").change(function(){ 
			
				setBankId($(this).children('option:selected').val());
			
		});
		
		
	}
	/**
	 * 选择银行卡
	 */

	var bankId="";

	function setBankId(id){
		
		bankId=id;
			
	}

	/**
	 * 打开绑定银行卡页面
	 */
	function bindingbankcardPage() {
		history.addHis(this,arguments);//增加历史
		var htmlStr="";
		
		htmlStr += '<div id="content-header"><div id="breadcrumb"> <a href=javascript:load("'+ddf.index.index_js+'") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href="javascript:$ddf_withdraw.showDiv("content0")>银行帐号管理</a><a href="javascript:void(0)" class="current">银行卡绑定</a></div></div>';
		htmlStr += '<div class="container-fluid">';
		htmlStr += '<div class="row-fluid">';
		htmlStr += '<div class="span12">';
		htmlStr += '<div id="alert-tips3" ></div>';
		
		htmlStr += '<div class="widget-box">';
		htmlStr += '<div class="widget-title"> <span class="icon"><i class="icon-th"></i></span>';
		htmlStr += '<h5>绑定银行卡</h5>';
		htmlStr += '</div>';
		htmlStr += '<div class="widget-content nopadding">';
		htmlStr += '<form class="form-horizontal">	   ';
		
		htmlStr += '<div class="control-group" id="control-group-bankId" >';
		htmlStr += '<label class="control-label">银行卡开户行：</label>';
		htmlStr += '<div class="controls">';
		htmlStr += '<input class="span4 alert_w"  id="input-bankCard" type="text" value="请选择银行卡开户行" readonly onclick="$ddf_withdraw.openBankCardDialog()" />';
		htmlStr += '</div>';
		htmlStr += '</div>';
		/*
		htmlStr += '<div class="control-group">';
		htmlStr += '<label class="control-label">账户类型：</label>';
		htmlStr += '<div class="controls">';
		htmlStr += '<div class="btn-group"><button data-toggle="dropdown" class="btn dropdown-toggle" ><span id="account_type_name">银行卡</span>&nbsp;&nbsp;<span class="caret"></span></button><ul class="dropdown-menu">';
		htmlStr += '<li><a href=javascript:$ddf_withdraw.setAccountType("00","银行卡")>银行卡</a></li>';
		htmlStr += '<li><a href=javascript:$ddf_withdraw.setAccountType("01","银行存折")>银行存折</a></li>';
		htmlStr += '</ul></div> ';
		htmlStr += '</div>    ';
		htmlStr += '</div>';
		*/
		htmlStr += '<div class="control-group" id="control-group-bankNumber">';
		htmlStr += '<label class="control-label">银行卡号：</label>';
		htmlStr += '<div class="controls">';
		htmlStr += '<input class="span4" type="text" id="input-bankNumber" value="">';
		htmlStr += '</div>              ';
		htmlStr += '</div>';

		htmlStr += '<div class="control-group" id="control-group-accountName">';
		htmlStr += '<label class="control-label">持卡人姓名：</label>';
		htmlStr += '<div class="controls">';
		htmlStr += '<input class="span4" type="text" id="input-accountName" value="">';
		htmlStr += '</div>              ';
		htmlStr += '</div>';
		/*
		htmlStr += '<div class="control-group">';
		htmlStr += '<label class="control-label">证件类型：</label>';
		htmlStr += '<div class="controls">';
		htmlStr += '<div class="btn-group">';
		htmlStr += '<button data-toggle="dropdown" class="btn dropdown-toggle" ><span id="card_type_name">身份证</span>&nbsp;&nbsp;<span class="caret"></span></button>';
		htmlStr += '<ul class="dropdown-menu">';
		htmlStr += '<li><a href=javascript:$ddf_withdraw.setCardType(1,"身份证")>身份证</a></li>';
		htmlStr += '<li><a href=javascript:$ddf_withdraw.setCardType(2,"军人证")>军人证</a></li>';
		htmlStr += '<li><a href=javascript:$ddf_withdraw.setCardType(3,"户口本")>户口本</a></li>';
		htmlStr += '</ul>';
		htmlStr += '</div>';
		htmlStr += '</div> ';
		htmlStr += '</div>';
		htmlStr += '<div class="control-group" id="control-group-identity">';
		htmlStr += '<label class="control-label">证件号码：</label>';
		htmlStr += '<div class="controls">';
		htmlStr += '<input class="span4" type="text" id="input-identity" value="">';
		htmlStr += '</div>       ';
		htmlStr += '</div>';
		
		htmlStr += '<div class="control-group" id="control-group-mobile">';
		htmlStr += '<label class="control-label">手机号码：</label>';
		htmlStr += '<div class="controls">';
		htmlStr += '<input class="span4" type="text" id="input-mobile">       ';
		htmlStr += '</div>                    ';
		htmlStr += '</div>';
		*/
		htmlStr += '<div class="control-group" >';
		htmlStr += '<label class="control-label"></label>';
		htmlStr += '<div class="controls">';
		htmlStr += '<input style="position: relative; top: 3px; z-index: 50;" id="defaultAcountCB" type="checkbox" value="true" checked="checked" onClick="$ddf_withdraw.setDefaultAcount()" />设为默认结算账户';
		htmlStr += '</div>             ';
		htmlStr += '</div>';
		/*
		htmlStr += '<div class="control-group" >';
		htmlStr += '<label class="control-label"></label>';
		htmlStr += '<div class="controls">';
		htmlStr += '<input style="position: relative; top: 3px; z-index: 50;"name="redisabledCB" id="redisabledCB" type="checkbox"onclick="$ddf_withdraw.redisabled()" onChange="$ddf_withdraw.redisabled()" /> 同意&nbsp;&nbsp;快捷支付服务协议&nbsp;&nbsp;，下次可凭卡号后4位快速付款';
		htmlStr += '</div>                  ';
		htmlStr += '</div>';
		*/
		
		htmlStr += '<div class="form-actions">';
		htmlStr += '<button class="btn btn-primary" id="btnBindBankCard" type="button" onclick="$ddf_withdraw.bindBankCard()" >绑定</button> ';
		htmlStr += '<button class="btn btn-info" type="button" onClick=$ddf_withdraw.showDiv("content0")>返回</button>  ';
		htmlStr += '</div>  ';
		htmlStr += '</form>';
		htmlStr += '</div>';
		htmlStr += '</div>  ';
		
		
		htmlStr += '</div>  ';
		htmlStr += '</div>';
		htmlStr += '</div> ';
		htmlStr += '</div> ';

		showDiv("content3");

		$("#content3").html(htmlStr);
		
		setRadioStyle();
		
		
		$("#input-bankNumber").change(function() {
			var bankNumber=$("#input-bankNumber").val();

			if(isNull(bankNumber)){
				base.clearErrorMessage("control-group-bankNumber");
				base.addErrorMessage("control-group-bankNumber","input-bankNumber","卡号非法");
				return;
			}else if(!isNumber(bankNumber)){
				base.clearErrorMessage("control-group-bankNumber");
				base.addErrorMessage("control-group-bankNumber","input-bankNumber","卡号必须全为数字");
				return;
			}else if(!isLength(bankNumber,8)){
				base.clearErrorMessage("control-group-bankNumber");
				base.addErrorMessage("control-group-bankNumber","input-bankNumber","卡号长度必须大于8位");
				return;
			}else{
				base.clearErrorMessage("control-group-bankNumber");
			}

		});
		
		$("#input-accountName").change(function() {

			var accountName=$("#input-accountName").val();

			if(isNull(accountName)){
				addErrorMessage("control-group-accountName","input-accountName","持卡人姓名非法");
			}else{
				clearErrorMessage("control-group-accountName");
			}

		});
	}

	/**
	 * 绑定银行卡
	 */
	function bindBankCard() {
		var bankNumber = $("#input-bankNumber").val();
		var accountName = $("#input-accountName").val();
//		var identity = $("#input-identity").val();
//		var mobile = $("#input-mobile").val();

//		if (bankId == "-1" || bankId == "") {
//			addErrorMessage("control-group-bankId", "input-bankCard", "请选择银行");
//			return;
//		}

		if(isNull(bankNumber)){
			base.clearErrorMessage("control-group-bankNumber");
			base.addErrorMessage("control-group-bankNumber","input-bankNumber","卡号非法");
			return;
		}else if(!isNumber(bankNumber)){
			base.clearErrorMessage("control-group-bankNumber");
			base.addErrorMessage("control-group-bankNumber","input-bankNumber","卡号必须全为数字");
			return;
		}else if(!isLength(bankNumber,8)){
			base.clearErrorMessage("control-group-bankNumber");
			base.addErrorMessage("control-group-bankNumber","input-bankNumber","卡号长度必须大于8位");
			return;
		}

		if (isNull(accountName)) {
			addErrorMessage("control-group-accountName", "input-accountName",
					"持卡人姓名非法");
			return;
		}

//		if (isNull(identity) || (!isNull(identity) && !isNumber(identity))) {
//			addErrorMessage("control-group-identity", "input-identity",
//					"证件号码非法");
//			return;
//		}

//		if (!isNull(mobile) && !isMobile(mobile)) {
//			addErrorMessage("control-group-mobile", "input-mobile", "手机号码非法");
//			return;
//		}

		var params = {

			"sgAccount.accountName" : accountName,
			"sgAccount.bankId" : bankId,
			"sgAccount.bankNumber" : bankNumber,
			"sgAccount.identifyTypeId" : identifyTypeId,
//			"sgAccount.identity" : identity,
//			"sgAccount.mobile" : mobile,
			"sgAccount.accountType" : accountType,
			"defaultaccount" : defaultAcount

		// ""
		};
		
		base.showLoading();

		eval(Wind.compile("async",function(){
			
			var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.withDrawSettle.getBindBankCard,params));
			
			bindBankCardCallBack(data);
			
		}))().start();

	}

	var bindBankFlag = false;
	/**
	 * 绑定银行卡_回调函数
	 * 
	 * @param data
	 */
	function bindBankCardCallBack(data) {
		cancelLoading();
		if (data["code"] == 1) {
			showDiv("content0");
			// tips(0,"添加银行卡成功");
			bindBankFlag = true;
			defaultAcount = "false";
			loadWithdrawList();
		} else {
			base.tips_error(data["message"]);
		}
		
	}

	/**
	 * 选择证件类型
	 */
	var identifyTypeId = "1";

	function setCardType(type, name) {

		identifyTypeId = type;

		$("#card_type_name").html(name);

	}

	var accountType = "00";
	function setAccountType(type, name) {
		accountType = type;
		$("#account_type_name").html(name);
	}

	/**
	 * 查询银行
	 */
	var out_put_bankId, setBankFlag = false;

	function getBankList(id, _bankId) {

		/*
		 * out_put_bankId=id;
		 * 
		 * if(_bankId!="") setBank(_bankId);
		 */

		eval(Wind.compile("async",function(){
			
			var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.bank.getBanksName,""));
			
			getBankListCallBack(data);
			
		}))().start();

	}

	/**
	 * 银行回调函数
	 */
	var bankListHtmlStr = "";

	function getBankListCallBack(data) {
		bankListHtmlStr = "";
		var htmlStr = "";
		for (var i = 0; i < data["resultBanksList"].length; i++) {
			if (i == 0)
				bankId = data["resultBanksList"][i]["bankNumber"];
			htmlStr += '<option value="'
					+ data["resultBanksList"][i]["bankNumber"] + '" >'
					+ data["resultBanksList"][i]["bankName"] + '</option>';
		}
		$("#select-bank").html(htmlStr);
		setSelectStyle();
		$("#select-bank").change(function() {
			setBankId($(this).children('option:selected').val());
		});
	}

	/**
	 * 设置是否选择默认
	 */
	var defaultAcount = "true";
	function setDefaultAcount() {
		if ($("#defaultAcountCB").is(":checked")) {
			defaultAcount = "true";
		} else {
			defaultAcount = "false";
		}
	}

	/**
	 * 是否已读条款
	 */
	function redisabled() {
		if ($("#redisabledCB").is(":checked")) {
			$("#btnBindBankCard").attr("disabled", false);
		} else {
			$("#btnBindBankCard").attr("disabled", true);
		}
	}

	/**
	 * 打开银行列表
	 */
	exports.openBankCardDialog=function(){

		dialog.ddf_dialog_bank($("#input-bankCard"),function(id,name){  
			
			$("#input-bankCard").val(name);
			
			setBankId(id);

			
	    });
		
	};
	
	
	/**
	 * 显示DIV
	 */
	function showDiv(block){
		
		$("#content > div").hide();
		
		if($("#"+block).length<=0){
			
			$("#content").append('<div id="'+block+'"></div>'); 
			
		}else{
			
			$("#"+block).show();
		}
		
		if(block=="content0"){
			shopTypeId="";
		}
		

		
	}
    exports.loadWithdrawList=loadWithdrawList; //加载提现记录
	exports.bindingbankcardPage = bindingbankcardPage; // 添加银行
	exports.nextStatus = nextStatus; // 下一步
	exports.queryWithdrawSettle = queryWithdrawSettle; // 查看提现记录
	exports.showDiv = showDiv; 
	exports.bindBankCard = bindBankCard; // 绑定
	exports.confirm = confirm; // 确认
	exports.redisabled = redisabled;
	exports.setCardType = setCardType; // 設置類型
	exports.setDefaultAcount = setDefaultAcount;// 設置默認用戶
	exports.withdrawResultPage = withdrawResultPage; // 提现的回调函数调用的方法
	exports.setAccountType = setAccountType; // 账户类型
	exports.setBankId = setBankId; // 设置银行代码
	exports.getBanksParamsCallBack=getBanksParamsCallBack;
});
